package com.yanqu.road.server.cmd.marriage;

import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.marriage.CrossUnionMarriageMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CANCEL_UNION_MARRIAGE, desc = "取消跨服商会联姻")
public class CrossUnionMarriageCancelCmd extends CrossCommand {
    private long userId;
    private String childUid;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MarriageProto.MarriageApplyCancelReqMsg reqMsg = MarriageProto.MarriageApplyCancelReqMsg.parseFrom(packet.getBytes());
        childUid = reqMsg.getChildUid();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ret = CrossUnionMarriageMgr.cancelMarriage(userId, childUid);
    }

    @Override
    public void sendData() {
        MarriageProto.MarriageApplyCancelRespMsg.Builder respMsg = MarriageProto.MarriageApplyCancelRespMsg.newBuilder();
        respMsg.setRet(ret);
        respMsg.setChildUid(childUid);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_UNION_MARRIAGE_CANCEL_RESP, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }
}
